<!DOCTYPE html>

<html>
<head>
  <title>Number</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
  <link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
  <div id="container">
    <div id="background"></div>
    
      <ul id="jump_to">
        <li>
          <a class="large" href="javascript:void(0);">Jump To &hellip;</a>
          <a class="small" href="javascript:void(0);">+</a>
          <div id="jump_wrapper">
          <div id="jump_page">
            
              
              <a class="source" href="Array.coffee.html">
                Array.coffee.md
              </a>
            
              
              <a class="source" href="BareObject.coffee.html">
                BareObject.coffee.md
              </a>
            
              
              <a class="source" href="Boolean.coffee.html">
                Boolean.coffee.md
              </a>
            
              
              <a class="source" href="Function.coffee.html">
                Function.coffee.md
              </a>
            
              
              <a class="source" href="Math.coffee.html">
                Math.coffee.md
              </a>
            
              
              <a class="source" href="Maybe.coffee.html">
                Maybe.coffee.md
              </a>
            
              
              <a class="source" href="Nullable.coffee.html">
                Nullable.coffee.md
              </a>
            
              
              <a class="source" href="Number.coffee.html">
                Number.coffee.md
              </a>
            
              
              <a class="source" href="Object.coffee.html">
                Object.coffee.md
              </a>
            
              
              <a class="source" href="Promise.coffee.html">
                Promise.coffee.md
              </a>
            
              
              <a class="source" href="String.coffee.html">
                String.coffee.md
              </a>
            
              
              <a class="source" href="Type.coffee.html">
                Type.coffee.md
              </a>
            
              
              <a class="source" href="header.coffee.html">
                header.coffee.md
              </a>
            
          </div>
        </li>
      </ul>
    
    <ul class="sections">
        
        
        
        <li id="section-1">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-1">&#182;</a>
              </div>
              <h1 id="number">Number</h1>

            </div>
            
            <div class="content"><div class='highlight'><pre>	
	Number.<span class="hljs-function"><span class="hljs-title">valid</span> = <span class="hljs-params">(value)</span> -&gt;</span> Object.isa(Number)(value) <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> isNaN value</pre></div></div>
            
        </li>
        
        
        <li id="section-2">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-2">&#182;</a>
              </div>
              <h2 id="predicates">Predicates</h2>

            </div>
            
            <div class="content"><div class='highlight'><pre>	
	<span class="hljs-attribute">Number</span>::equals = Function.From<span class="hljs-function"><span class="hljs-params">(Number)</span> <span class="hljs-params">(x)</span> -&gt;</span> Number(<span class="hljs-keyword">this</span>) == Number(x)</pre></div></div>
            
        </li>
        
        
        <li id="section-3">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-3">&#182;</a>
              </div>
              <h2 id="operators">Operators</h2>

            </div>
            
            <div class="content"><div class='highlight'><pre>	
	<span class="hljs-attribute">Number</span>::plus = Function.From<span class="hljs-function"><span class="hljs-params">(Number)</span> <span class="hljs-params">(x)</span> -&gt;</span> <span class="hljs-keyword">this</span> + x
	
	<span class="hljs-attribute">Number</span>::minus = Function.From<span class="hljs-function"><span class="hljs-params">(Number)</span> <span class="hljs-params">(x)</span> -&gt;</span> <span class="hljs-keyword">this</span> - x
	
	<span class="hljs-attribute">Number</span>::times = Function.From<span class="hljs-function"><span class="hljs-params">(Number)</span> <span class="hljs-params">(x)</span> -&gt;</span> <span class="hljs-keyword">this</span> * x
	
	<span class="hljs-attribute">Number</span>::div =  Function.From<span class="hljs-function"><span class="hljs-params">(Number)</span> <span class="hljs-params">(x)</span> -&gt;</span> <span class="hljs-keyword">this</span> / x
	
	<span class="hljs-attribute">Number</span>::mod =  Function.From<span class="hljs-function"><span class="hljs-params">(Number)</span>  <span class="hljs-params">(x)</span> -&gt;</span> <span class="hljs-keyword">this</span> % x
	
	<span class="hljs-attribute">Number</span>::map = Function.From<span class="hljs-function"><span class="hljs-params">(Function)</span> <span class="hljs-params">(fn)</span> -&gt;</span> fn.call <span class="hljs-keyword">this</span>, <span class="hljs-keyword">this</span></pre></div></div>
            
        </li>
        
        
        <li id="section-4">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-4">&#182;</a>
              </div>
              <h2 id="restrictions">Restrictions</h2>

            </div>
            
            <div class="content"><div class='highlight'><pre>	
	Number.In = Function.From<span class="hljs-function"><span class="hljs-params">([Number])</span>.<span class="hljs-title">To</span><span class="hljs-params">(Function)</span> <span class="hljs-params">(numbers...)</span> -&gt;</span>
		<span class="hljs-property">@Where</span> \
			<span class="hljs-function"><span class="hljs-params">(number)</span> -&gt;</span> number <span class="hljs-keyword">in</span> numbers,
			<span class="hljs-string">"Invalid Number: \"&lt;value&gt;\" is not in {<span class="hljs-subst">#{(number <span class="hljs-keyword">for</span> number <span class="hljs-keyword">in</span> numbers ).join(<span class="hljs-string">','</span>)}</span>}"</span>
	
	Number.LessThan = Function.From<span class="hljs-function"><span class="hljs-params">(Number)</span>.<span class="hljs-title">To</span><span class="hljs-params">(Function)</span> <span class="hljs-params">(max)</span> -&gt;</span>
		<span class="hljs-property">@Where</span> Function.lt(max), <span class="hljs-string">"Invalid Value: &lt;value&gt; is not less than <span class="hljs-subst">#{max}</span>"</span>
		
	Number.GreaterThan = Function.From<span class="hljs-function"><span class="hljs-params">(Number)</span>.<span class="hljs-title">To</span><span class="hljs-params">(Function)</span> <span class="hljs-params">(min)</span> -&gt;</span>
		<span class="hljs-property">@Where</span> Function.gt(min), <span class="hljs-string">"Invalid Value: &lt;value&gt; is not greater than <span class="hljs-subst">#{min}</span>"</span>

	Number.Between = Function.From<span class="hljs-function"><span class="hljs-params">(Number,Number)</span>.<span class="hljs-title">To</span><span class="hljs-params">(Function)</span> <span class="hljs-params">(min,max)</span> -&gt;</span>
		<span class="hljs-property">@Where</span> Function.between(min,max), <span class="hljs-string">"Invalid Value: &lt;value&gt; is not between <span class="hljs-subst">#{min}</span> and <span class="hljs-subst">#{max}</span>"</span>
	
	Number.Integer = Number.Where (<span class="hljs-function">-&gt;</span> <span class="hljs-property">@equals</span> Math.round <span class="hljs-keyword">this</span> ), <span class="hljs-string">"Invalid Value: &lt;value&gt; is not an integer"</span>

	Number.Positive = Number.GreaterThan <span class="hljs-number">0</span>
	Number.Negative = Number.LessThan <span class="hljs-number">0</span>
	
	Number.Odd  = Number.Integer.Where (<span class="hljs-function">-&gt;</span> <span class="hljs-number">1</span> == <span class="hljs-property">@mod</span> <span class="hljs-number">2</span>), <span class="hljs-string">"Invalid Value: &lt;value&gt; is not odd"</span>
	Number.Even = Number.Integer.Where (<span class="hljs-function">-&gt;</span> <span class="hljs-number">0</span> == <span class="hljs-property">@mod</span> <span class="hljs-number">2</span>), <span class="hljs-string">"Invalid Value: &lt;value&gt; is not even"</span></pre></div></div>
            
        </li>
        
    </ul>
  </div>
</body>
</html>
